package cn.yunhe.action;

import cn.yunhe.entity.Member;
import cn.yunhe.entity.Role;
import cn.yunhe.service.MemberBizEntity;
import cn.yunhe.util.BaseActionUtil;
import com.opensymphony.xwork2.ModelDriven;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.util.Iterator;


public class MemberEntityAction extends BaseActionUtil implements ModelDriven {

    @Autowired
    @Qualifier(value = "memberBizEntity")
    private MemberBizEntity memberBizEntity;

    private Member member;

    public String login(){
        Member member1=memberBizEntity.login(member);
        System.out.println(member1.getMid());
        System.out.println(member1.getRoleSet());
        System.out.println(member1.getRoleSet().iterator().next().getPermissionSet());

        //判定角色,是否为超级管理员
        Iterator<Role>iterator= member1.getRoleSet().iterator();
        while (iterator.hasNext()){
            Role role= iterator.next();
            System.out.println(role.getRname());
            getRequest().setAttribute("admin",member1);
            return "admin";
        }
        getRequest().setAttribute("member",member1);
        return SUCCESS;
    }

    public MemberBizEntity getMemberBizEntity() {
        return memberBizEntity;
    }

    public void setMemberBizEntity(MemberBizEntity memberBizEntity) {
        this.memberBizEntity = memberBizEntity;
    }

    public Member getMember() {
        return member;
    }

    public void setMember(Member member) {
        this.member = member;
    }

    @Override
    public Object getModel() {
        if (member==null)
            member=new Member();
        return member;
    }
}
